<template>
    <div class="tr">
        <div class="tr-top">
            <div class="left">
                <!-- <div class="itm"><el-button >新增</el-button></div> -->

            </div>
            <div class="right">
                <div class="itm"> <el-input :disabled="props.type__like == 'timertask' ? false : true" clearable
                        v-model="tableObjData.type__like" style="width: 240px" placeholder="输入类型" /></div>
                <div class="itm"> <el-input clearable v-model="tableObjData.name" style="width: 240px"
                        placeholder="输入任务名称" /></div>
                <div class="itm"><el-button @click="getEv(true)">查询</el-button></div>
            </div>
        </div>
        <div class="table-content">
            <el-table empty-text="暂无数据" border height="100%" :data="tableListData">
                <el-table-column align="center" type="index" label="#" width="50" />
                <el-table-column align="center" header-align="center" show-overflow-tooltip prop="name" label="名称"
                    width="150" />
                <el-table-column align="center" header-align="center" label="状态" width="120">
                    <template #default="scope">
                        <el-tag v-if="scope.row.status == true" type="success">成功</el-tag>
                        <el-tag v-else type="danger">失败</el-tag>
                    </template>
                </el-table-column>
                <el-table-column align="center" header-align="center" prop="create_time" label="执行时间" width="180" />
                <el-table-column align="center" header-align="center" show-overflow-tooltip prop="order" label="单号/编码"
                    width="150">
                    <template #default="scope">
                        {{ scope.row.order }}
                    </template>
                </el-table-column>
                <el-table-column align="center" header-align="center" show-overflow-tooltip prop="data" label="推送数据"
                    width="150">
                    <template #default="scope">
                        <el-button link @click="onClickOutside(scope.row.data)">{{ scope.row.data }}</el-button>
                    </template>
                </el-table-column>
                <el-table-column align="center" header-align="center" show-overflow-tooltip prop="rem" label="消息中心">
                    <template #default="scope">
                        <el-button link @click="onClickOutside(scope.row.rem)">{{ scope.row.rem }}</el-button>
                    </template>
                </el-table-column>
            </el-table>

        </div>
        <pagination v-show="tableObjData.total > 0" :total="tableObjData.total" v-model:page="tableObjData.page"
            v-model:limit="tableObjData.pageSize" @pagination="getEv(true)" />
    </div>
</template>

<script setup>
import { TimerTaskLogsListGet } from '@/api/setting/timerTask/index.js'
import { ref, reactive, onMounted, onActivated } from 'vue'
import { loadingStore } from '@/stores/index.js'

const props = defineProps(['type__like', 'task_name'])
// 顶部菜单数据

const loading = loadingStore()

const tableListData = ref([])


let tableObjData = reactive({
    label__like: '',
    name: '',
    type__like: '',
    page: 1,
    total: 0,
    has_next: false,
    has_prev: false,
    pages: 0,
    pageSize: 20
})

onMounted(() => {
    // getEv(false)
})
onActivated(() => {

})
const onClickOutside = (data) => {
    ElMessageBox.alert(data, '详情', {
        confirmButtonText: '关闭',
        draggable: true,
        showConfirmButton:false,
        closeOnPressEscape:false
    })

}
// 查询数据
const getEv = async (msg) => {
    loading.loading = true
    if (props.type__like != 'timertask') {
        tableObjData.type__like = props.type__like
    }
    console.log(props.task_name, 22)
    if (props.type__like != '') {
        tableObjData.name = props.task_name
    }
    try {
        let arr_data = await TimerTaskLogsListGet(tableObjData)
        if (arr_data.status != 200) {
            return
        }
        if (msg == true) {
            ElMessage.success('查询成功')
        }
        tableListData.value = arr_data.data.result.data
        tableObjData.total = arr_data.data.result.total
        tableObjData.has_next = arr_data.data.result.has_next
        tableObjData.has_prev = arr_data.data.result.has_prev
        tableObjData.pages = arr_data.data.result.pages
        // tableObjData.pageSize = arr_data.data.result.pageSize

    } catch (error) {
        ElMessage.error('查询接口请求失败' + error)
    } finally {
        loading.loading = false
    }
}
defineExpose({
    getEv

})
</script>

<style lang='less' scoped>
.tr {
    height: 100%;
    width: 100%;
}

.tr-top {
    height: var(--tr-top-height);
    display: flex;
    align-items: center;
    justify-content: space-between;

    .left {
        display: flex;
        align-items: center;
    }

    .right {
        display: flex;
        align-items: center;
    }

    .itm {
        padding-right: 4px;
        box-sizing: border-box;
    }
}

.table-content {
    height: calc(100% - var(--tr-top-height) - var(--tr-page-height));
}
</style>